from PyQt4 import QtGui, QtCore
from PyQt4.QtCore import Qt, QString
from .msg_lamp import MiniLed
from .brass_plate import BrassPlate

class Msg_NewsBar_LEDs(QtGui.QWidget):
        def __init__(self, *args, **kw):
		QtGui.QWidget.__init__(self, *args, **kw)

		#bg = QtGui.QLabel(self)
		#path = "resources/mini_led_panel.png"
		#bg.setPixmap(QtGui.QPixmap(path))

		x = 3
		xinc = 11
		led = MiniLed(self, "red")
		led.move(x,2)
		led.turn_off()
		self.urgent = led

		led = MiniLed(self, "cyan")
		led.move(x,14)
		led.turn_off()
		self.personal = led

		x += xinc
		led = MiniLed(self, "pink")
		led.move(x,2)
		led.turn_off()
		self.tarts = led

		led = MiniLed(self, "darkblue")
		led.move(x,14)
		led.turn_off()
		self.ruffians = led

		x += xinc
		led = MiniLed(self, "green")
		led.move(x,2)
		led.turn_off()
		self.houses = led

		led = MiniLed(self, "yellow")
		led.move(x,14)
		led.turn_off()
		self.adversaries = led

		x += xinc
		led = MiniLed(self, "purple")
		led.move(x,2)
		led.turn_off()
		self.news = led

		led = MiniLed(self, "orangered")
		led.move(x,14)
		led.turn_off()
		self.gossip = led

class Msg_Newsplate(QtGui.QWidget):
        def __init__(self, *args, **kw):
		QtGui.QWidget.__init__(self, *args, **kw)

		bg = BrassPlate(self)
		bg.setGeometry(0,0,216,32)

		ledbox = BrassPlate(self)
		ledbox.setGeometry(3,3,49,26)

		capbox = BrassPlate(self)
		capbox.setGeometry(54,3,160,26)
		self.texty = QtGui.QLabel(self)
		self.texty.setGeometry(56,5,156,22)
		font = QtGui.QFont("Times New Roman", 14)
		self.texty.setFont(font)

		leds = Msg_NewsBar_LEDs(self)
		leds.move(3,3)

		self.adversaries= leds.adversaries
		self.gossip     = leds.gossip
		self.houses     = leds.houses
		self.news       = leds.news
		self.personal   = leds.personal
		self.ruffians   = leds.ruffians
		self.tarts      = leds.tarts
		self.urgent     = leds.urgent

	def set_text(self, s):
		self.texty.setText(s)

	def set_flags(self, flag_names):
		for f in flag_names:
			if f in [
				"adversaries", "gossip", "houses", "news",
				"personal", "ruffians", "tarts", "urgent"
			]:
				self.__dict__[f].turn_on()

class MsgNewspanel(QtGui.QWidget):
        def __init__(self, *args, **kw):
		QtGui.QWidget.__init__(self, *args, **kw)

		top = QtGui.QLabel(self)
		top.setGeometry(0, 0, 244, 563)
		path = "resources/newsframe.png"
		top.setPixmap(QtGui.QPixmap(path))

		self.plates = []
		for i in range(16):
			panel = Msg_Newsplate(self)
			panel.move(14, 18 + i* 33)
			panel.hide()
			self.plates.append(panel)

		#panel.personal.turn_on()
		#panel.set_text("Apothecary")

	def set_events(self, elist):
		for i, e in enumerate(elist):
			if i > len(self.plates):
				break
			plate = self.plates[i]
			plate.set_text(e.label)
			plate.set_flags(e.flags)
			plate.show()

if __name__ == "__main__":
	import sys
	app = QtGui.QApplication(sys.argv)

	class EventGroup:
		def __init__(self, **kw):
			self.__dict__.update(kw)
		def __str__(self):
			return "Event Group: {}".format(
				self.label
			)

#
#	use the wallpaper as the top level widget
#
	top = QtGui.QLabel()
	top.setGeometry(0, 0, 300, 600)
	path = "resources/wood.jpg"
	top.setPixmap(QtGui.QPixmap(path))

	ll = [
		EventGroup(
			label	= "Apothecary",
			flags	= [ "personal" ]
		),
		EventGroup(
			label	= "'Luckless' Johnson",
			flags	= [ "ruffians", "urgent" ]
		),
		EventGroup(
			label	= "Annabelle",
			flags	= [ "tarts" ]
		)

	]

	panel = MsgNewspanel(top)
	panel.move(20, 20)
	panel.set_events(ll)

	top.show()
	sys.exit(app.exec_())
